import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './router_config'
Vue.use(VueRouter)

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
//拦截登陆状态
router.beforeEach((to, from, next) => {
    let { fullPath, meta: { requireLogin } } = to
    // console.log(fullPath,requireLogin);
    if (requireLogin) {
        if ((sessionStorage.getItem('loginInfo'))) {
            next()
        } else {
            window.sessionStorage.setItem('fullPath', fullPath)
            next({ path: '/login' })
        }
    } else {
        next()
    }
    // console.log(to,from);
})
export default router